//
//  CustomTabButton.m
//  星期一
//
//  Created by 来定MAC on 15/7/21.
//  Copyright (c) 2015年 LD. All rights reserved.
//

#import "CustomTabButton.h"

@interface CustomTabButton ()

@property (weak, nonatomic) IBOutlet UILabel *title;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (strong,nonatomic)UIImage *image;
@property (strong,nonatomic)UIImage *seletedImage;
@property (assign,nonatomic)BOOL seleted;

@end

@implementation CustomTabButton

- (instancetype)init
{
    self = [super init];
    if (self) {
        
        self = [[[NSBundle mainBundle] loadNibNamed:@"CustomTabButton" owner:nil options:nil]lastObject];
        
        UITapGestureRecognizer *tapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickSelf)];
        [self addGestureRecognizer:tapGes];
    }
    return self;
}

+ (instancetype)customTabButton
{
    return [[self alloc] init];
}

- (void)title:(NSString *)title image:(UIImage *)image selectedImage:(UIImage *)selectedImage
{
    [self.title setText:title];
    self.image = image;
    self.seletedImage = selectedImage;
}

- (void)showFromSelectedStatus:(BOOL) seleted
{
    self.seleted = seleted;
    if (seleted) {
        
        [self.title setTextColor:[UIColor colorWithRed:228/255 green:8/255 blue:57/255 alpha:1]];
        [self.imageView setImage:self.seletedImage];
    }else
    {
        [self.title setTextColor:[UIColor colorWithRed:46/255 green:46/255 blue:46/255 alpha:1]];
        [self.imageView setImage:self.image];
    }
}

- (void)clickSelf
{
    if (self.selectedBlock) {
        self.selectedBlock(self);
        //通知代理
        [self.delegate customTabButton:self];
    }
}




@end
